package com.oa.modules.approvalsec1.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.oa.modules.approvalsec1.entity.DictionaryEntity;
import com.oa.modules.approvalsec1.service.DictionaryService;
import com.oa.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.oa.common.utils.PageUtils;
import com.oa.common.utils.R;

/**
 * 项目流程材料表
 *
 * @author yangwenzhi
 * @email 785297226@qq.com
 * @date 2022-01-17 16:56:19
 */
@RestController
@RequestMapping("dictionary")
@Api(tags = "项目流程材料表相关接口")
public class DictionaryController extends AbstractController {
    @Autowired
    private DictionaryService dictionaryService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = dictionaryService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "信息")
    public R info(@PathVariable("id") Integer id){
		DictionaryEntity dictionary = dictionaryService.getById(id);
        return R.ok().put("dictionary", dictionary);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public R save(@RequestBody DictionaryEntity dictionary){
        dictionary.setCreateDate(new Date());
        dictionary.setCreateOper(getUserId().toString());
		dictionaryService.save(dictionary);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public R update(@RequestBody DictionaryEntity dictionary){
        dictionary.setUpdateDate(new Date());
        dictionary.setUpdateOper(getUserId().toString());
		dictionaryService.updateById(dictionary);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public R delete(@RequestBody Integer[] ids){
		dictionaryService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
    /**
     * 信息
     */
    @GetMapping("/get")
    @ApiOperation(value = "信息")
    public R get(Integer itemId){
        QueryWrapper<DictionaryEntity> wrapper = new QueryWrapper<DictionaryEntity>().eq("item_id", itemId);
        DictionaryEntity entity = dictionaryService.getOne(wrapper);
        return R.ok().put("dictionary", entity);
    }
}
